//==========================================================
// 此代码由TilverNET代码生成工具自动生成，请不要修改
// 代码生成器版本号：1.2
// 作者：landy
// 联系方式：(QQ)86566178
// 创建时间：2014/2/18 16:52:42
//==========================================================

using System;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using System.Linq;
using Tilver.Data;
using Tilver.Data.DataPager;

namespace Tilver.Oracle.DAL.Scott
{
	#region EO

	/// <summary>
	///  《SCOTT.SALGRADE(实体类)》
	/// </summary>
	[Serializable]
	public class SALGRADEEO : IRowMapper<SALGRADEEO>
	{
		protected decimal? _gRADE;
		protected decimal? _lOSAL;
		protected decimal? _hISAL;


		/// <summary>
		///  《[字段]  [NUMBER]》
		/// </summary>
		public decimal? GRADE
		{
			get { return _gRADE; }
			set { _gRADE = value;}
		}

		/// <summary>
		///  《[字段]  [NUMBER]》
		/// </summary>
		public decimal? LOSAL
		{
			get { return _lOSAL; }
			set { _lOSAL = value;}
		}

		/// <summary>
		///  《[字段]  [NUMBER]》
		/// </summary>
		public decimal? HISAL
		{
			get { return _hISAL; }
			set { _hISAL = value;}
		}

		/// <summary>
		/// 默认构造函数
		/// </summary>
		public SALGRADEEO() 
		{
		}

		/// <summary>
		/// 自定义构造函数
		/// </summary>
		/// <param name = "gRADE"></param>
		/// <param name = "lOSAL"></param>
		/// <param name = "hISAL"></param>
		public SALGRADEEO(decimal? gRADE, decimal? lOSAL, decimal? hISAL) 
		{
			_gRADE = gRADE;
			_lOSAL = lOSAL;
			_hISAL = hISAL;
		}


		/// <summary>
		/// 将结果集映射成实体对象
		/// </summary>
		/// <param name = "reader">只进结果集流</param>
		/// <return></return>
		public SALGRADEEO MapRow(IDataReader reader)
		{
			var ret = new SALGRADEEO();
			ret.GRADE = (reader["GRADE"] is DBNull) ? null : (decimal?)reader["GRADE"];
			ret.LOSAL = (reader["LOSAL"] is DBNull) ? null : (decimal?)reader["LOSAL"];
			ret.HISAL = (reader["HISAL"] is DBNull) ? null : (decimal?)reader["HISAL"];
			return ret;
		}

		/// <summary>
		/// 将结果集映射成实体对象，返回映射方法
		/// </summary>
		/// <return></return>
		public Func<IDataReader, SALGRADEEO> GetMapper()
		{
			return MapRow;
		}


	}


	#endregion
	#region MO

	/// <summary>
	///  《SCOTT.SALGRADE(逻辑类)》
	/// </summary>
	public class SALGRADEMO : DbManagerBase
	{

		#region 构造函数
		/// <summary>
		/// 构造函数
		/// </summary>
		/// <param name = "routeData">路由数据</param>
		public SALGRADEMO(object routeData = null) : base(routeData) { }

		/// <summary>
		/// 构造函数
		/// </summary>
		/// <param name = "connectionStringName">连接字符串名称</param>
		public SALGRADEMO(string connectionStringName) : base(connectionStringName) { }

		#endregion

		#region 私有方法
		/// <summary>
		/// 数据库访问操作方法
		/// </summary>
		/// <param name = "sql">SQL语句</param>
		/// <return>返回数据操作对象</return>
		private DbAdoBase AdoBase(string sql)
		{
			return DataBase.CreateDbAdo(sql, CommandType.Text);
		}

		#endregion

		#region Select方法集合

		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "gRADE"></param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<SALGRADEEO> SelectByGRADE(decimal? gRADE, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} ""GRADE"", ""LOSAL"", ""HISAL"" FROM ""SCOTT"".""SALGRADE"" WHERE ""GRADE""=:GRADE");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), string.Empty);
			sql.Append((top > 0) ? ((sql.ToString().IndexOf("WHERE", StringComparison.OrdinalIgnoreCase) > 0) ? string.Format(" AND ROWNUM<={0} ", top) : string.Format(" WHERE ROWNUM<={0} ", top)) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter(":GRADE", gRADE, DbType.VarNumeric, 0)
							.ExecuteList(new SALGRADEEO().GetMapper(), tm);
		}
		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "lOSAL"></param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<SALGRADEEO> SelectByLOSAL(decimal? lOSAL, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} ""GRADE"", ""LOSAL"", ""HISAL"" FROM ""SCOTT"".""SALGRADE"" WHERE ""LOSAL""=:LOSAL");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), string.Empty);
			sql.Append((top > 0) ? ((sql.ToString().IndexOf("WHERE", StringComparison.OrdinalIgnoreCase) > 0) ? string.Format(" AND ROWNUM<={0} ", top) : string.Format(" WHERE ROWNUM<={0} ", top)) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter(":LOSAL", lOSAL, DbType.VarNumeric, 0)
							.ExecuteList(new SALGRADEEO().GetMapper(), tm);
		}
		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "hISAL"></param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<SALGRADEEO> SelectByHISAL(decimal? hISAL, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} ""GRADE"", ""LOSAL"", ""HISAL"" FROM ""SCOTT"".""SALGRADE"" WHERE ""HISAL""=:HISAL");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), string.Empty);
			sql.Append((top > 0) ? ((sql.ToString().IndexOf("WHERE", StringComparison.OrdinalIgnoreCase) > 0) ? string.Format(" AND ROWNUM<={0} ", top) : string.Format(" WHERE ROWNUM<={0} ", top)) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter(":HISAL", hISAL, DbType.VarNumeric, 0)
							.ExecuteList(new SALGRADEEO().GetMapper(), tm);
		}

		/// <summary>
		/// 按自定义条件查询
		/// </summary>
		/// <param name = "where">自定义条件,where子句</param>
		/// <param name = "top">获取行数</param>
		/// <param name = "sort">排序表达式</param>
		/// <param name = "paras">where子句中定义的参数集合</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<SALGRADEEO> Select(string where, int top, string sort, IEnumerable<DbParameter> paras, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} ""GRADE"", ""LOSAL"", ""HISAL"" FROM ""SCOTT"".""SALGRADE"" ");
			if (!string.IsNullOrEmpty(where)) format.AppendFormat(" WHERE {0} ", where);
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), string.Empty);
			sql.Append((top > 0) ? ((sql.ToString().IndexOf("WHERE", StringComparison.OrdinalIgnoreCase) > 0) ? string.Format(" AND ROWNUM<={0} ", top) : string.Format(" WHERE ROWNUM<={0} ", top)) : string.Empty);
			return AdoBase(sql.ToString())
							.AddParameters(paras)
							.ExecuteList(new SALGRADEEO().GetMapper(), tm);
		}

		/// <summary>
		/// 分页查询
		/// </summary>
		/// <param name = "where">条件表达式</param>
		/// <param name = "sort">排序表达式</param>
		/// <param name = "paras">传入参数</param>
		/// <param name = "pageSize">页大小</param>
		/// <param name = "pageIndex">页码</param>
		/// <param name = "recordCount">总记录数，由于计算总记录数影响数据库性能，只有小于或等于0的情况下才返回总记录数</param>
		/// <return>分页数据</return>
		public List<SALGRADEEO> SelectPager(string where, string sort, IList<DbParameter> paras, long pageSize, long pageIndex, ref long recordCount)
		{
			var sql = new StringBuilder();
			sql.AppendFormat(@"SELECT ""GRADE"", ""LOSAL"", ""HISAL"" FROM ""SCOTT"".""SALGRADE""");
			if (!string.IsNullOrEmpty(where)) sql.AppendFormat(" WHERE {0} ", where);
			if (!string.IsNullOrEmpty(sort)) sql.AppendFormat(" ORDER BY {0} ", sort);
			var pager = this.DataBase.CreatePager(sql.ToString(), pageSize);
			pager.AddParameters(paras);
			if (recordCount <= 0)
			{
				recordCount = pager.GetRecordCount();
			}
			return pager.GetPageData(pageIndex).MapToList(new SALGRADEEO().GetMapper());
		}

		#endregion

		#region Insert方法集合
		/// <summary>
		/// 插入数据，有自增列时，item中自增字段为新增值，否则，返回影响的行数
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "item">要插入的实体对象</param>
		/// <return></return>
		public int Insert(SALGRADEEO item, TransactionManager tm = null)
		{
			const string sql = @"INSERT INTO ""SCOTT"".""SALGRADE"" (""GRADE"", ""LOSAL"", ""HISAL"") VALUES (:GRADE, :LOSAL, :HISAL) ";
			return AdoBase(sql)
												.AddInParameter(":GRADE", item.GRADE.HasValue ? (object)item.GRADE.Value : DBNull.Value, DbType.VarNumeric, 0)
												.AddInParameter(":LOSAL", item.LOSAL.HasValue ? (object)item.LOSAL.Value : DBNull.Value, DbType.VarNumeric, 0)
												.AddInParameter(":HISAL", item.HISAL.HasValue ? (object)item.HISAL.Value : DBNull.Value, DbType.VarNumeric, 0)
												.ExecuteNonQuery(tm);
		}
		#endregion

		#region Update方法集合
		/// <summary>
		/// 按自定义条件更新数据
		/// </summary>
		/// <param name = "set">更新列</param>
		/// <param name = "where">更新条件</param>
		/// <param name = "paras">参数集合</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public int Update(string set, string where, IEnumerable<DbParameter> paras, TransactionManager tm = null)
		{
			if (string.IsNullOrEmpty(set)) throw new ArgumentNullException("set");
			var sql = string.Format(@"UPDATE ""SCOTT"".""SALGRADE"" SET {0} {1}", set, (string.IsNullOrEmpty(where) ? string.Empty : " WHERE " + where));
			return AdoBase(sql)
							.AddParameters(paras)
							.ExecuteNonQuery(tm);
		}
		#endregion

		#region Delete方法集合
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "gRADE"></param>
		public int DeleteByGRADE(decimal? gRADE, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM ""SCOTT"".""SALGRADE"" WHERE ""GRADE""=:GRADE";
			return AdoBase(sql)
							.AddInParameter(":GRADE", gRADE.HasValue ? (object)gRADE.Value : DBNull.Value, DbType.VarNumeric, 0)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "lOSAL"></param>
		public int DeleteByLOSAL(decimal? lOSAL, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM ""SCOTT"".""SALGRADE"" WHERE ""LOSAL""=:LOSAL";
			return AdoBase(sql)
							.AddInParameter(":LOSAL", lOSAL.HasValue ? (object)lOSAL.Value : DBNull.Value, DbType.VarNumeric, 0)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "hISAL"></param>
		public int DeleteByHISAL(decimal? hISAL, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM ""SCOTT"".""SALGRADE"" WHERE ""HISAL""=:HISAL";
			return AdoBase(sql)
							.AddInParameter(":HISAL", hISAL.HasValue ? (object)hISAL.Value : DBNull.Value, DbType.VarNumeric, 0)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 删除指定条件的记录
		/// </summary>
		/// <param name = "whereClause">自定义删除条件，where子句。如：id=1 and name='aaa'</param>
		/// <param name = "paras">where子句中定义的参数集合</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public int Delete(string whereClause, IEnumerable<DbParameter> paras, TransactionManager tm = null)
		{
			var sql = string.Format(@"DELETE FROM ""SCOTT"".""SALGRADE"" {0}", (string.IsNullOrEmpty(whereClause) ? string.Empty : " WHERE " + whereClause));
			return AdoBase(sql)
							.AddParameters(paras)
							.ExecuteNonQuery(tm);
		}
		#endregion

		#region  自定义方法集合
		#endregion

	}


	#endregion
}
